package com.kongl.lottery.user.controller;

import com.kongl.lottery.user.entity.User;
import com.kongl.lottery.user.repository.UserRepository;
import com.kongl.lottery.user.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.DigestUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserRepository userRepository;

    @PostMapping("/login")
    public ResultVo<User> login(String email, String password){
        User user=userRepository.findByEmailAndPassword(email,DigestUtils.md5DigestAsHex(password.getBytes()));
        if (user!=null){
            return ResultVo.success(user);
        }else {
            return ResultVo.error("用户信息不存在");
        }

    }
}
